//
//  ChapterViewController.m
//  AssistantDriving
//
//  Created by dcr on 2017/8/28.
//  Copyright © 2017年 邓兆太. All rights reserved.
//

#import "ChapterViewController.h"
#import "AnswerViewController.h"
#import "SelectModel.h"
#import "SectionModel.h"
#import "ChapterCell.h"

@interface ChapterViewController ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation ChapterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UITableView *table = [self tableView];
    [self.view addSubview:table];
    table.dataSource = self;
    table.delegate = self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ChapterCell * cell = [ChapterCell cellWithTableView:tableView];
    if(_model == chapterPractice){
        SelectModel *model = _datas[indexPath.row];
        cell.indexLabel.text = model.pid;
        cell.titleLabel.text = model.pname;
    }else if(_model == specialPractice){
        SectionModel *model = _datas[indexPath.row];
        cell.indexLabel.text = model.serial;
        cell.titleLabel.text = model.sname;
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    AnswerViewController *controller = [[AnswerViewController alloc]init];
    if(_model == chapterPractice){
        controller.number = (int)indexPath.row;
        controller.model = chapterPractice;
    }else if(_model == specialPractice){
        SectionModel *model = _datas[indexPath.row];
        controller.number = (int)indexPath.row;
        controller.mtype = model.sid;
        controller.model = specialPractice;
    }
    [self.navigationController showViewController:controller sender:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
